define(function (require,exports,modules) {
    let $=require("jquery");
    require("jquery.validate");
    require("additional-methods");
    $.validator.addMethod("checkEmail",function (val,ele) {
        return /^(.)+@(.)+\.(.)+$/.test(val);
    })
    $.validator.addMethod("checkName",function (val,ele) {
        return /^1\d{10}$/.test(val);
    })
    $.validator.addMethod("checkPwd",function (val,ele) {
        return /^\w{6,16}$/.test(val);
    })
    let reg=function () {
        $("form").validate({
            rules:{
                uemail:{
                    required:true,
                    checkEmail:true,
                    remote:{
                        url:"../../server/checkemail.php",
                        type:"get",
                        dataType:"json",
                        data:{
                            "uemail":function () {
                                return $("[name=uemail]").val();
                            }
                        }
                    }
                },
                uname:{
                    required:true,
                    checkName:true,
                    remote:{
                        url:"../../server/checkname.php",
                        type:"get",
                        dataType:"json",
                        data:{
                            "uname":function () {
                                return $("[name=uname]").val();
                            }
                        }
                    }
                },
                upwd:{
                    required:true,
                    checkPwd:true
                },
                upwd2:{
                    required:true,
                    equalTo:"#upwd"
                }
            },
            messages:{
                uemail:{
                    required:"请输入邮箱",
                    checkEmail:"邮箱不合法",
                    remote:"邮箱已存在"
                },
                uname:{
                    required:"请输入手机号",
                    checkName:"11位手机号码",
                    remote:"手机已存在"
                },
                upwd:{
                    required:"请输入密码",
                    checkPwd:"密码为6-16位数字字母或下划线"
                },
                upwd2:{
                    required:"请再次输入密码",
                    equalTo:"两次密码不一致"
                }
            },
            submitHandler:function () {
                $.ajax({
                    url:"../../server/register.php",
                    type:"post",
                    dataType:"json",
                    data:$("form").serialize()
                }).then(function (res) {

                    if(res.status==1){
                        alert(res.msg);
                        location="login.html";
                    }
                })

                return false;
            },
            errorPlacement:function (err,ele) {
                $(ele).after(err);
                $(ele).siblings(".tip_icon").addClass("tip_error");
            },
            success:function (err,ele) {

                $(ele).parent().find(".tip_icon").removeClass("tip_error").addClass("tip_right");
            }
        })

    }

    exports.reg=reg;
})